
/****
 * Copyright (C) 2006 dNux Team
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

#ifndef __DCORE_MAP_H__
#define __DCORE_MAP_H__

typedef d_list_t d_map_t;
typedef d_list_iterator_t d_map_iterator_t;
typedef d_list_free_f d_map_free_f;

typedef struct _d_map_data_s {
  d_map_free_f f_free;
  char *key;
  void *value;
} d_map_data_t;


#define d_map_new() (d_map_t*) d_list_new_with_free_func(d_map_data_free)
#define d_map_free(map) d_list_free((d_list_t **)map)
#define d_map_free_iterator(iterator) \
  d_list_free_iterator((d_list_iterator_t **) iterator)

#define d_map_push(map, data) _d_list_add((d_list_t *) map, (void *) data, \
					 d_false)
#define d_map_pushback(map, data) _d_list_add((d_list_t *) map, \
					      (void *) data, d_true)
#define d_map_del(iterator) d_list_del((d_list_iterator_t *) iterator)
#define d_map_clear(map) d_list_clear((d_list_t *) map)
#define d_map_length(map) d_list_length((d_list_t *) map)
#define d_map_iterator_valid(iterator) \
  d_list_iterator_valid((d_list_iterator_t *) iterator)
#define d_map_at(map, pos) \
  (d_map_iterator_t *) d_list_at((d_list_t *) map, pos)

#define d_map_data(iterator, var) \
  _d_list_value((d_list_iterator_t *) iterator, (void **) var)

#define d_map_begin(map) (d_map_iterator_t *) d_list_begin((d_list_t *) map)
#define d_map_end(map) (d_map_iterator_t *) d_list_end((d_list_t *) map)

#define d_map_prev(iterator) d_list_prev((d_list_iterator_t **) iterator)
#define d_map_next(iterator) d_list_next((d_list_iterator_t **) iterator)

d_map_data_t *d_map_data_new(char *key, void *value, d_map_free_f f_free);
void          d_map_data_free(void *data);

d_map_iterator_t *d_map_find(d_map_t *map, const char *key);

#endif /* __DCORE_MAP_H__ */
